package com.tensquare.notice.controller;

import com.tensquare.notice.pojo.Notice;
import com.tensquare.notice.service.NoticeService;
import entity.PageResult;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/notice")
public class NoticeController {

    @Autowired
    NoticeService noticeService;

    //1. 根据id查询消息通知
    //2. 根据条件分页查询消息通知
    //3. 新增通知
    //4. 修改通知
    //5. 根据用户id查询该用户的待推送消息（新消息）
    //6. 删除待推送消息（新消息）

    //通过id查询消息

    //根据id查询消息通知
    @RequestMapping(value = "{id}",method = RequestMethod.GET)
    public Result findById(@PathVariable String id) {
        Notice byId = noticeService.findById(id);
        return new Result(true, StatusCode.OK,null,byId);
    }

    //根据条件分页查询
    @RequestMapping(value = "/search/{page}/{size}",method = RequestMethod.POST)
    public Result findById(@PathVariable Integer page,
                                       @PathVariable Integer size,
                                       @RequestBody(required = false) Notice notice) {
        List<Notice> byPage = noticeService.findByPage(page, size, notice);
        PageResult<Notice> noticePageResult = new PageResult<>();
        noticePageResult.setRows(byPage);
        long size1 = byPage.size();
        noticePageResult.setTotal(size1);
        return new Result(true, StatusCode.OK,null,noticePageResult);
    }

    //更加id分页查询待发送消息




}
